package com.mugui.base.client.net.bagsend;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.digest.MD5;
import com.mugui.base.client.net.baghandle.NetHandle;
import com.mugui.base.client.net.bean.Message;
import com.mugui.base.client.net.bean.NetBag;

import kotlin.Function;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.math.BigInteger;

public class NetCall  {

    @Getter
    private String id=idFunction.getID();

    @Getter
    @Setter
    private String threadName;

    public static class IDFunction{
        private final  String key= new BigInteger(System.nanoTime()+"").toString(16);
        public String getID(){
            return key+":"+IdUtil.fastSimpleUUID();
        }
    }

    private static IDFunction idFunction=new IDFunction();
    public static void setIDFunction(
            @NonNull
            IDFunction function){
        idFunction=function;
    }

    @Getter
    private String func;

    public NetCall(String func) {
        this.func = func;
    }

    public static abstract class  Call{


        /**
         * 透传数据包
         */
        @Setter
        @Getter
        @Accessors(chain = true)
        private Object[] datas;

       abstract public Message ok(Message data);
       abstract public  Message err(Message data);
    }

    /**
     * 判断是否有处理器
     * @return
     */
    public boolean isCall(){
        return main!=null||son!=null;
    }
    /**
     * 主线程
     */
    @Getter
    private Call main=null;
    /**
     * 子线程
     */
    @Getter
    private Call son=null;




    /**
     * 主线程
     */
    public NetCall main(Call call){
        main=call;
        return this;
    }

    /**
     *子线程
     * @param call
     * @return
     */
    public NetCall son(Call call){
        son=call;
        return this;
    }

}
